home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / src / sprited / fsconsist / fsconsist.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  8.4 KB  |  224 lines

  1. /*
  2.  * fsconsist.h --
  3.  *
  4.  *    Declarations for cache consistency routines.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /r3/kupfer/spriteserver/src/sprited/fsconsist/RCS/fsconsist.h,v 1.3 91/12/01 21:58:30 kupfer Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _FSCONSIST
  20. #define _FSCONSIST
  21.  
  22. #include <ckalloc.h>
  23.  
  24. #if defined(KERNEL) || defined(SPRITED)
  25. #include <fs.h>
  26. #include <fsio.h>
  27. #include <rpc.h>
  28. #else
  29. #include <kernel/fs.h>
  30. #include <kernel/fsio.h>
  31. #include <kernel/rpc.h>
  32. #endif
  33. /*
  34.  * Flags to determine what type of consistency operation is required.
  35.  *
  36.  *        FSCONSIST_WRITE_BACK_BLOCKS    Write back all dirty blocks.
  37.  *        FSCONSIST_INVALIDATE_BLOCKS    Invalidate all block in the cache for this
  38.  *                file.  This means that the file is no longer
  39.  *                cacheable.
  40.  *        FSCONSIST_DELETE_FILE        Delete the file from the local cache and
  41.  *                the file handle table.
  42.  *        FSCONSIST_CANT_CACHE_NAMED_PIPE    The named pipe is no longer read cacheable
  43.  *                on the client.  This would happen if two
  44.  *                separate clients tried to read the named pipe
  45.  *                at the same time.
  46.  *    FSCONSIST_WRITE_BACK_ATTRS    Write back the cached attributes.
  47.  *    FSCONSIST_DEBUG    Forces machine into debugger
  48.  *    FSCONSIST_MIGRATION    Consistency operation is due to migration
  49.  *                (for statistics purposes).
  50.  */
  51.  
  52. #define    FSCONSIST_WRITE_BACK_BLOCKS        0x01
  53. #define    FSCONSIST_INVALIDATE_BLOCKS        0x02
  54. #define    FSCONSIST_DELETE_FILE            0x04
  55. #define    FSCONSIST_CANT_CACHE_NAMED_PIPE        0x08
  56. #define    FSCONSIST_WRITE_BACK_ATTRS        0x10
  57. #define FSCONSIST_DEBUG                0x100
  58. #define    FSCONSIST_MIGRATION            0x200
  59.  
  60. /*
  61.  * The client use state needed to allow remote client access and to
  62.  * enforce network cache consistency.  A list of state for each client
  63.  * using the file is kept, including the name server itself.  This
  64.  * is used to determine what cache consistency actions to take.
  65.  * There is synchronization over this list between subsequent open
  66.  * operations and the cache consistency actions themselves.
  67.  */
  68.  
  69. typedef struct Fsconsist_Info {
  70.     Sync_Lock    lock;        /* Monitor lock used to synchronize access
  71.                  * to cache consistency routines and the
  72.                  * consistency list. */
  73.     int        flags;        /* Flags defined in fsCacheConsist.c */
  74.     int        lastWriter;    /* Client id of last client to have it open
  75.                    for write caching. */
  76.     int        openTimeStamp;    /* Generated on the server when the file is
  77.                  * opened.  Checked on clients to catch races
  78.                  * between open replies and consistency
  79.                  * messages */
  80.     Fs_HandleHeader *hdrPtr;    /* Back pointer to handle header needed to
  81.                  * identify the file. */
  82.     List_Links    clientList;    /* List of clients of this file.  Scanned
  83.                  * to determine cachability conflicts */
  84.     List_Links    msgList;    /* List of outstanding cache
  85.                  * consistency messages. */
  86.     Sync_Condition consistDone;    /* Opens block on this condition
  87.                  * until ongoing cache consistency
  88.                  * actions have completed */
  89.     Sync_Condition repliesIn;    /* This condition is notified after
  90.                  * all the clients told to take
  91.                  * consistency actions have replied. */
  92. } Fsconsist_Info;
  93.  
  94. /*
  95.  * Structure to contain information for each client that is using a file.
  96.  */
  97.  
  98. typedef struct Fsconsist_ClientInfo {
  99.     List_Links    links;        /* This hangs in a list off the I/O handle */
  100.     int        clientID;    /* The sprite ID of this client. */
  101.     Fsio_UseCounts use;        /* Usage info for the client.  Used to clean
  102.                  * up summary counts when client crashes. */
  103.     /*
  104.      * The following fields are only used by regular files.
  105.      */
  106.     Boolean    cached;        /* TRUE if the file is cached on this client. */
  107.     int        openTimeStamp;    /* The most recent open of this file. */
  108.     Boolean    locked;        /* TRUE when a pointer is held to this client
  109.                  * list element.  It is not appropriate to
  110.                  * garbage collect the element when set. */
  111.     Boolean    mapped;        /* TRUE if the client is mapping the
  112.                  * file into memory. */
  113. } Fsconsist_ClientInfo;
  114.  
  115. /*
  116.  * INSERT_CLIENT takes care of initializing a new client list entry.
  117.  */
  118. #define INSERT_CLIENT(clientList, clientPtr, clientID) \
  119.     fs_Stats.object.fileClients++;        \
  120.     clientPtr = mnew(Fsconsist_ClientInfo);    \
  121.     clientPtr->clientID = clientID;        \
  122.     clientPtr->use.ref = 0;            \
  123.     clientPtr->use.write = 0;            \
  124.     clientPtr->use.exec = 0;            \
  125.     clientPtr->openTimeStamp = 0;        \
  126.     clientPtr->cached = FALSE;            \
  127.     clientPtr->locked = FALSE;            \
  128.     clientPtr->mapped = FALSE;            \
  129.     List_InitElement((List_Links *)clientPtr);    \
  130.     List_Insert((List_Links *) clientPtr, LIST_ATFRONT(clientList));
  131.  
  132. /*
  133.  * REMOVE_CLIENT takes care of removing a client list entry.
  134.  */
  135. #define REMOVE_CLIENT(clientPtr) \
  136.     fs_Stats.object.fileClients--;        \
  137.     List_Remove((List_Links *) clientPtr);    \
  138.     ckfree((Address) clientPtr);
  139.  
  140. #if defined(KERNEL) || defined(SPRITED)
  141. /*
  142.  * This header file (fsioFile.h) is needed to define Fsio_FileIOHandle for the
  143.  * function prototypes below. It must occur after Fsconsist_Info is defined.
  144.  */
  145. #include <fsioFile.h>
  146. /*
  147.  * Client list routines.
  148.  */
  149. extern void Fsconsist_ClientInit _ARGS_((void));
  150. extern Fsconsist_ClientInfo *Fsconsist_IOClientOpen _ARGS_((
  151.             List_Links *clientList, int clientID, int useFlags,
  152.             Boolean cached));
  153. extern Boolean Fsconsist_IOClientReopen _ARGS_((List_Links *clientList, 
  154.             int clientID, Fsio_UseCounts *usePtr));
  155. extern Boolean Fsconsist_IOClientClose _ARGS_((List_Links *clientList, 
  156.             int clientID, int flags, Boolean *cachePtr));
  157. extern Boolean Fsconsist_IOClientRemoveWriter _ARGS_((List_Links *clientList,
  158.             int clientID));
  159. extern void Fsconsist_IOClientKill _ARGS_((List_Links *clientList, int clientID,
  160.             int *refPtr, int *writePtr, int *execPtr));
  161. extern void Fsconsist_IOClientStatus _ARGS_((List_Links *clientList, 
  162.             int clientID, Fsio_UseCounts *clientUsePtr));
  163.  
  164.  
  165.  
  166. /*
  167.  * Cache consistency routines.
  168.  */
  169. extern void Fsconsist_Init _ARGS_(( Fsconsist_Info *consistPtr,
  170.             Fs_HandleHeader *hdrPtr));
  171. extern void Fsconsist_SyncLockCleanup _ARGS_((Fsconsist_Info *consistPtr));
  172. extern ReturnStatus Fsconsist_MappedConsistency _ARGS_((
  173.             Fsio_FileIOHandle *handlePtr, int clientID, 
  174.             int isMapped));
  175. extern ReturnStatus Fsconsist_FileConsistency _ARGS_((
  176.             Fsio_FileIOHandle *handlePtr, int clientID, 
  177.             int useFlags, Boolean *cacheablePtr, 
  178.             int *openTimeStampPtr));
  179.  
  180. extern void Fsconsist_ReopenClient _ARGS_((Fsio_FileIOHandle *handlePtr, 
  181.             int clientID, Fsio_UseCounts use, 
  182.             Boolean haveDirtyBlocks));
  183. extern ReturnStatus Fsconsist_ReopenConsistency _ARGS_((
  184.             Fsio_FileIOHandle *handlePtr, int clientID, 
  185.             Fsio_UseCounts use, int swap, Boolean *cacheablePtr, 
  186.             int *openTimeStampPtr));
  187. extern ReturnStatus Fsconsist_MigrateConsistency _ARGS_((
  188.             Fsio_FileIOHandle *handlePtr, int srcClientID, 
  189.             int dstClientID, int useFlags, Boolean closeSrc, 
  190.             Boolean *cacheablePtr, int *openTimeStampPtr));
  191. extern void Fsconsist_GetClientAttrs _ARGS_((Fsio_FileIOHandle *handlePtr, 
  192.             int clientID, Boolean *isExecedPtr));
  193. extern Boolean Fsconsist_Close _ARGS_((register Fsconsist_Info *consistPtr, 
  194.             int clientID, int flags, Boolean *wasCachedPtr));
  195.  
  196. extern void Fsconsist_DeleteLastWriter _ARGS_((Fsconsist_Info *consistPtr, 
  197.             int clientID));
  198. extern void Fsconsist_ClientRemoveCallback _ARGS_((Fsconsist_Info *consistPtr,
  199.             int clientID));
  200. extern void Fsconsist_Kill _ARGS_((Fsconsist_Info *consistPtr, int clientID, 
  201.             int *refPtr, int *writePtr, int *execPtr));
  202. extern void Fsconsist_GetAllDirtyBlocks _ARGS_((int domain, Boolean invalidate));
  203. extern void Fsconsist_FetchDirtyBlocks _ARGS_((Fsconsist_Info *consistPtr, 
  204.             Boolean invalidate));
  205.  
  206. extern ReturnStatus Fsconsist_RpcConsist _ARGS_((ClientData srvToken, 
  207.             int clientID, int command, Rpc_Storage *storagePtr));
  208. extern ReturnStatus Fsconsist_RpcConsistReply _ARGS_((ClientData srvToken, 
  209.             int clientID, int command, Rpc_Storage *storagePtr));
  210.  
  211.  
  212. #ifdef SOSP91
  213. extern int Fsconsist_NumClients _ARGS_((Fsconsist_Info *consistPtr,
  214.                     int *numReadPtr, int *numWritePtr));
  215. #else
  216. extern int Fsconsist_NumClients _ARGS_((Fsconsist_Info *consistPtr));
  217. #endif
  218.  
  219. extern void Fsconsist_AddClient _ARGS_((int clientID));
  220.  
  221. #endif /* KERNEL || SPRITED */
  222.  
  223. #endif /* _FSCONSIST */
  224.